from typing import Optional, List, Union

from fastapi import FastAPI, Header, HTTPException
from starlette import status

app = FastAPI()


async def validate_perms(
        perms: Union[List[str], None] = None,
        institution_id: Union[List[str], None] = None,
        co_inst_ids: Union[List[str], None] = None,

) -> Optional[List[str]]:
    """
    perms: list[]
    institution_id: 主办
    co_inst_ids: 协办
    """
    perms = perms or []
    institution_id = institution_id or []
    co_inst_ids = co_inst_ids or []
    filter_ids = set(perms) & set(institution_id) & set(co_inst_ids)
    return list(filter_ids)


async def jwt_auth(authorization: str = Header(default=None)):
    pass
    # if authorization == "Bearer eyJhbGciOiJIUzI1NiJ9.eyJSb2xlIjoiZWxvbiIsIklzc3VlciI6Iklzc3VlciIsIlVzZXJuYW1lIjo" \
    #                     "ic3BhY2V4IiwiZXhwIjoxNjgzMTY2NDQ2LCJpYXQiOjE2ODMxNjY0NDZ9.vbkPZnBVE8cFuQ0T9KXtG6rZGReo9Q" \
    #                     "yuesvbPlrrzSw":
    #     pass
    # else:
    #     raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Token header invalid")
